package com.yuyang.wifi.js.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.yuyang.wifi.R;
import com.yuyang.wifi.constant.ConstantsMsg;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, ConstantsMsg.WE_CHAT_APP_ID);

        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }


    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp resp) {
        switch (resp.errCode) {
            case 0:
                Toast.makeText(this, "支付成功", Toast.LENGTH_SHORT).show();
                finish();
                break;
            case -1:
                Toast.makeText(this, "付款失败", Toast.LENGTH_SHORT).show();
                finish();
                break;
            case -2:
                Toast.makeText(this, "支付取消", Toast.LENGTH_SHORT).show();
                finish();
                break;
        }
    }
}